package com.flejay.core.generic.dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class CrudServiceDaoImpl<T> implements ICrudServiceDao<T>{
	
	@Autowired
	protected SessionFactory sessionFactory;
	
	@Override
	public void persist(T resource){
		this.sessionFactory.getCurrentSession().persist(resource);
	}
	
	@Override
	public void update(T resource){
		this.sessionFactory.getCurrentSession().update(resource);
	}
	
	@Override
	public void delete(T resource){
		this.sessionFactory.getCurrentSession().delete(resource);
	}
	
	@Override
	@SuppressWarnings("unchecked")
	public T findById(Class c,long id){
		return (T) sessionFactory.getCurrentSession().get(c, id);
	}
	
	public Session getCurrentSession(){
		return this.sessionFactory.getCurrentSession();
	}
	
}
